//
// @header Cache.m
//  Pictorial
//
// @abstract #关于此文件的描述#
// @author Created by SKY on 15/12/30.
// @version #版本号# 15/12/30Creation
//  Copyright © 2015年 sky. All rights reserved.
//

#import "Cache.h"
#import <SDWebImageManager.h>
@implementation Cache

+(NSString *)cachePath{
    NSArray *library = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
    NSString *libraryPath = [library firstObject];
    NSString *cachePath = [NSString stringWithFormat:@"%@/Caches",libraryPath];
    return cachePath;
}

+(NSString *)cacheSize{
    
    NSString *cachePath = [Cache cachePath];
    
    NSFileManager *manager = [NSFileManager defaultManager];
    
    //子文件
    NSArray *subPaths = [manager subpathsOfDirectoryAtPath:cachePath error:nil];
    
    long long sumSize = 0;
    
    for (NSString *subPath in subPaths) {
        NSString *filePath = [cachePath stringByAppendingFormat:@"/%@",subPath];
        long long size = [[manager attributesOfItemAtPath:filePath error:nil] fileSize];
        sumSize += size;
    }
    float fileSize = sumSize / (1024 * 1024);
    return [NSString stringWithFormat:@"%.2fM",fileSize];
}

+(void)cleanCache{
    
    NSFileManager *manager = [NSFileManager defaultManager];
    
    NSString *cachePath = [Cache cachePath];

    [manager removeItemAtPath:cachePath error:nil];
 
    [[SDWebImageManager sharedManager].imageCache clearMemory];
    [[SDWebImageManager sharedManager].imageCache clearDisk];

}

@end
